package com.ssm.studen.controller;

import com.ssm.studen.model.Exampaperanswer;
import com.ssm.studen.service.ExampaperanswerService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 试卷答题表：
 *          对外提供数据服务接口
 */
@Api(tags = "exampaperanswer")
@RestController
public class ExampaperanswerController {

    @Autowired
    private ExampaperanswerService exampaperanswerService;

    /******************试卷答题表查询*******************/
    @ApiOperation("试卷答题表查询")
    @RequestMapping(value = "/selectExampaperanswer",method = RequestMethod.PUT)
    public ResponseMessage selectExampaperanswer(int epanum){
        Map<String,List> map = new HashMap<>();
        List<Exampaperanswer> listExampaperanswer = exampaperanswerService.selectExampaperanswer(epanum);
        map.put("list",listExampaperanswer);
        return Result.success("200",map);
    }


    /******************试卷答题表添加*******************/
    @ApiOperation("试卷答题表添加")
    @RequestMapping(value = "/insertExampaperanswer",method = RequestMethod.GET)
    public int insertExampaperanswer(Exampaperanswer exampaperanswer){
        int isAdd = 0;
        if(exampaperanswer != null){
            if(exampaperanswer.getEqpnum()!=0&&
                    exampaperanswer.getEpaistrue()!=null&&
                    exampaperanswer.getEparesult()!=null&&
                    exampaperanswer.getAnum()!=0){
                isAdd = exampaperanswerService.insertExampaperanswer(exampaperanswer);
            }
        }
        return isAdd;
    }


    /******************试卷答题表更新*******************/
    @ApiOperation("试卷答题表更新")
    @RequestMapping(value = "/updateExampaperanswer",method = RequestMethod.GET)
    public ResponseMessage updateExampaperanswer(Exampaperanswer exampaperanswer){
        //传入的参数不能为空
        if(exampaperanswer != null){
            //参数当中主键不能为0
            if(exampaperanswer.getEpanum()!=0){
                if(exampaperanswerService.updateExampaperanswer(exampaperanswer) == 1){
                    if(exampaperanswer.getEqpnum()!=0&&
                            exampaperanswer.getEpaistrue()!=null&&
                            exampaperanswer.getEparesult()!=null&&
                            exampaperanswer.getAnum()!=0){
                        exampaperanswerService.updateExampaperanswer(exampaperanswer);
                    }
                    return Result.success("更新成功");
                }else{
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入参数不正确");
    }
}











